package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberMapper;
import com.itheima.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;
import java.util.Map;


@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberMapper memberMapper;

    @Override
    public Member findByTelephone(String telephone) {
        return memberMapper.findByTelephone(telephone);
    }

    @Override
    public Member add(Member member) {
        memberMapper.add(member);
        return member;
    }

    @Override
    public void saveMember(Member member) {
        memberMapper.saveMember(member);
    }

    @Override
    public List<Member> getFamily(Integer id) {
        //根据当前登录用户id查询用户的家庭联系人
        List<Member> members = memberMapper.findMemberByParentId(id);

        // 把自己的信息查询出来
        Member member = memberMapper.findMemberById(id);

        members.add(member);
        return members;
    }

    @Override
    public Member findMemberById(Integer id) {
        Member member = memberMapper.findMemberById(id);
        return member;
    }


    @Override
    public Member addFamily(Member member) {
        memberMapper.addFamily(member);
        return  member;
    }

    @Override
    public List<Member> editFamily(Integer id) {
        //根据当前登录用户id查询用户的家庭联系人
        List<Member> members = memberMapper.findMemberByParentId(id);

        // 把自己的信息查询出来
        Member member = memberMapper.findMemberById(id);

        members.add(member);
        return members;
    }


}
